/**
 * @file exercise_outdoor_running.c
 *
 */

/*********************
*      INCLUDES
*********************/
#include "exercise.h"

#if USE_LV_WATCH_EXERCISE != 0

/*********************
*      DEFINES
*********************/
#define EXERCISE_GOALS_MIN_DISTANCE_VALUE            (1)
#define EXERCISE_GOALS_MAX_DISTANCE_VALUE            (100)
#define EXERCISE_GOALS_DISTANCE_STEP                 (1)
#define EXERCISE_GOALS_DEF_CUSTOM_DISTANCE_VALUE     (21)

#define EXERCISE_GOALS_MIN_TIME_VALUE                (10)
#define EXERCISE_GOALS_MAX_TIME_VALUE                (1440)
#define EXERCISE_GOALS_TIME_STEP                     (5)
#define EXERCISE_GOALS_DEF_CUSTOM_TIME_VALUE         (30)

#define EXERCISE_GOALS_MIN_CALORIE_VALUE             (100)
#define EXERCISE_GOALS_MAX_CALORIE_VALUE             (5000)
#define EXERCISE_GOALS_CALORIE_STEP                  (50)
#define EXERCISE_GOALS_DEF_CUSTOM_CALORIE_VALUE      (300)

/**********************
*      TYPEDEFS
**********************/

/**********************
*  STATIC PROTOTYPES
**********************/

/**********************
*  STATIC VARIABLES
**********************/

/**********************
*      MACROS
**********************/

/**********************
 *   STATIC FUNCTIONS
 **********************/
static void exercise_start_cb(exercise_start_desc_t * desc)
{
    if(NULL == desc) {
        printf("%s: warning, desc is NULL\n", __FUNCTION__);
        return;
    }

    printf("%s\n", __FUNCTION__);

    desc->ui_count = 6;

    desc->ui_desc[0].arc_type = EXERCISE_ARC_TYPE_HR;
    desc->ui_desc[0].ui_type = EXERCISE_START_UI_TYPE_4_ITEMS_WITH_TIME;
    desc->ui_desc[0].item_type[0] = EXERCISE_START_UI_ITEM_TYPE_HEART_RATE;
    desc->ui_desc[0].item_type[1] = EXERCISE_START_UI_ITEM_TYPE_PACE;
    desc->ui_desc[0].item_type[2] = EXERCISE_START_UI_ITEM_TYPE_DISTANCE;
    desc->ui_desc[0].item_type[3] = EXERCISE_START_UI_ITEM_TYPE_DURATION;

    desc->ui_desc[1].arc_type = EXERCISE_ARC_TYPE_HR;
    desc->ui_desc[1].ui_type = EXERCISE_START_UI_TYPE_3_ITEMS_WITH_TIME;
    desc->ui_desc[1].item_type[0] = EXERCISE_START_UI_ITEM_TYPE_STEP_NUMBER;
    desc->ui_desc[1].item_type[1] = EXERCISE_START_UI_ITEM_TYPE_STRIDE_FREQUENCY;
    desc->ui_desc[1].item_type[2] = EXERCISE_START_UI_ITEM_TYPE_CALORIE;

    desc->ui_desc[2].arc_type = EXERCISE_ARC_TYPE_HR;
    desc->ui_desc[2].ui_type = EXERCISE_START_UI_TYPE_2_ITEMS_WITH_TIME;
    desc->ui_desc[2].item_type[0] = EXERCISE_START_UI_ITEM_TYPE_CUMULATIVELY_CLIMB;
    desc->ui_desc[2].item_type[1] = EXERCISE_START_UI_ITEM_TYPE_HEIGHT;

    desc->ui_desc[3].arc_type = EXERCISE_ARC_TYPE_HR;
    desc->ui_desc[3].ui_type = EXERCISE_START_UI_TYPE_1_ITEM_WITH_TIME;
    desc->ui_desc[3].item_type[0] = EXERCISE_START_UI_ITEM_TYPE_HEART_RATE;

    desc->ui_desc[4].arc_type = EXERCISE_ARC_TYPE_NONE;
    desc->ui_desc[4].ui_type = EXERCISE_START_UI_TYPE_RUNNING_WITH_AI;
    // relative distance,heart rate and average pace will be display on the running with ai ui
#if 0
    desc->ui_desc[4].item_type[0] = EXERCISE_START_UI_ITEM_TYPE_RELATIVE_DISTANCE;
    desc->ui_desc[4].item_type[1] = EXERCISE_START_UI_ITEM_TYPE_HEART_RATE;
    desc->ui_desc[4].item_type[2] = EXERCISE_START_UI_ITEM_TYPE_AVERAGE_PACE;
#endif

    desc->ui_desc[5].arc_type = EXERCISE_ARC_TYPE_TRAINING_EFFECT;
    desc->ui_desc[5].ui_type = EXERCISE_START_UI_TYPE_TRAINING_EFFECT;
    desc->ui_desc[5].item_type[0] = EXERCISE_START_UI_ITEM_TYPE_AEROBIC_TRAINING;
    desc->ui_desc[5].item_type[1] = EXERCISE_START_UI_ITEM_TYPE_ANAEROBIC_TRAINING;
}

static void exercise_get_roller_desc_cb(EXERCISE_VALUE_TYPE_T type, exercise_roller_desc_t * desc)
{
    if(NULL == desc) {
        printf("%s: warning, desc is NULL\n", __FUNCTION__);
        return;
    }

    if(EXERCISE_VALUE_TYPE_DISTANCE == type) {
        uint16_t value[EXERCISE_MAX_ROLLER_VALUE_NUM] = {1, 3, 5, 10,
                                                        EXERCISE_GOALS_DISTANCE_HALF_MARATHON,
                                                        EXERCISE_GOALS_DISTANCE_MARATHON};
        Hal_Mem_Copy(desc->value, value, EXERCISE_MAX_ROLLER_VALUE_NUM * sizeof(uint16_t));
        desc->custom_min = EXERCISE_GOALS_MIN_DISTANCE_VALUE;
        desc->custom_max = EXERCISE_GOALS_MAX_DISTANCE_VALUE;
        desc->custom_step = EXERCISE_GOALS_DISTANCE_STEP;
        desc->custom_default = EXERCISE_GOALS_DEF_CUSTOM_DISTANCE_VALUE;
    } else if(EXERCISE_VALUE_TYPE_TIME == type) {
        uint16_t value[EXERCISE_MAX_ROLLER_VALUE_NUM] = {10, 20, 30, 60, 120, 180};
        Hal_Mem_Copy(desc->value, value, EXERCISE_MAX_ROLLER_VALUE_NUM * sizeof(uint16_t));
        desc->custom_min = EXERCISE_GOALS_MIN_TIME_VALUE;
        desc->custom_max = EXERCISE_GOALS_MAX_TIME_VALUE;
        desc->custom_step = EXERCISE_GOALS_TIME_STEP;
        desc->custom_default = EXERCISE_GOALS_DEF_CUSTOM_TIME_VALUE;
    } else if(EXERCISE_VALUE_TYPE_CALORIE == type) {
        uint16_t value[EXERCISE_MAX_ROLLER_VALUE_NUM] = {100, 200, 300, 500, 600, 800};
        Hal_Mem_Copy(desc->value, value, EXERCISE_MAX_ROLLER_VALUE_NUM * sizeof(uint16_t));
        desc->custom_min = EXERCISE_GOALS_MIN_CALORIE_VALUE;
        desc->custom_max = EXERCISE_GOALS_MAX_CALORIE_VALUE;
        desc->custom_step = EXERCISE_GOALS_CALORIE_STEP;
        desc->custom_default = EXERCISE_GOALS_DEF_CUSTOM_CALORIE_VALUE;
    } else {
        printf("%s: warning, invalid type %d\n", __FUNCTION__, type);
    }
}

/**********************
 *   GLOBAL FUNCTIONS
 ***********************/
void exercise_outdoor_running_get_sport_info(exercise_sport_info_t * info)
{
    Hal_Mem_Set(info, 0, sizeof(exercise_sport_info_t));

    info->img_src = ICON_EXERCISE_RUNNING;

    info->img_bg_color = LV_COLOR_MAKE(248, 99, 46);

    info->txt_id = WATCH_TEXT_ID_OUTDOOR_RUNNING;

    info->is_wait_gps = true;

    info->start_cb = exercise_start_cb;

    info->setting_item_bitmap |= 1 << EXERCISE_SETTING_ITEM_TYPE_SMART_COACH;
    info->setting_item_bitmap |= 1 << EXERCISE_SETTING_ITEM_TYPE_GOALS;
    info->setting_item_bitmap |= 1 << EXERCISE_SETTING_ITEM_TYPE_REMINDER;
    info->setting_item_bitmap |= 1 << EXERCISE_SETTING_ITEM_TYPE_INTEL_RUN_COMP;

    info->goals_item_bitmap |= 1 << EXERCISE_VALUE_TYPE_DISTANCE;
    info->goals_item_bitmap |= 1 << EXERCISE_VALUE_TYPE_TIME;
    info->goals_item_bitmap |= 1 << EXERCISE_VALUE_TYPE_CALORIE;

    info->reminder_item_bitmap |= 1 << EXERCISE_REMINDER_ITEM_TYPE_INTERVAL;
    info->reminder_item_bitmap |= 1 << EXERCISE_REMINDER_ITEM_TYPE_HEART_RATE;
    info->reminder_item_bitmap |= 1 << EXERCISE_REMINDER_ITEM_TYPE_TRAINING_EFFECT;
    info->reminder_item_bitmap |= 1 << EXERCISE_REMINDER_ITEM_TYPE_PHYSICAL_STATE;

    info->interval_reminder_item_bitmap |= 1 << EXERCISE_VALUE_TYPE_DISTANCE;
    info->interval_reminder_item_bitmap |= 1 << EXERCISE_VALUE_TYPE_TIME;

    info->roller_cb = exercise_get_roller_desc_cb;
}

#endif /*USE_LV_WATCH_EXERCISE*/
